﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FortuneHeaven.Entity.Accounts;
using Jzy.Core.Common;
using FortuneHeaven.DAL.Accounts;
using FortuneHeaven.Entity.GameScore;
using FortuneHeaven.BLL.GameScore;

namespace FortuneHeaven.BLL.Accounts
{
    public class AccountsBO : CommonOperate<AccountsInfo>
    {
        private AccountsDAL _accounts;
        public AccountsBO()
        {
          
            _accounts = new AccountsDAL();
            base.dbOper = _accounts.dbOper;
        }

        public override AccountsInfo GetInfo(object id)
        {
            return _accounts.GetInfo(id);
        }

        public override List<AccountsInfo> GetList(PagerSetting pager, params object[] conditionParas)
        {
            List<AccountsInfo> list = base.GetList(pager, conditionParas);
            GameScoreBO score= new GameScoreBO();
            List<GameScoreInfo> scoreList = score.GetList(list.Select(T => T.UserID));

            foreach (AccountsInfo info in list)
            {
                IEnumerable<GameScoreInfo> tmp = scoreList.Where(T => T.UserID == info.UserID);
                if (tmp.Count() > 0)
                {
                    GameScoreInfo tmpInfo = tmp.First();
                    info.Score = tmpInfo.Score;
                    info.LostCount = tmpInfo.LostCount;
                    info.WinCount = tmpInfo.WinCount;
                }
            }

            return list;
        }

        public AccountsInfo GetInfobyAccount(string accountName)
        {
            return _accounts.GetInfobyAccount(accountName);
        }

        public int GetRegisterCount(int netBarID)
        {
            return _accounts.GetRegisterCount(netBarID);

        }

        public int GetTodayRegisterCount(int netBarID, DateTime date)
        {
            return _accounts.GetTodayRegisterCount(netBarID, date);

        }

        public long GetTotalScore(int netBarID)
        {
            return _accounts.GetTotalScore(netBarID);
                
        }

        public int GetMemberCount(int netBarID)
        {
            return _accounts.GetMemberCount(netBarID);
        }
    }
}
